app.controller('BusVehicleShiftListCtrl', function ($scope, ajax, $modal, toaster,$stateParams) {

	$scope.tplId=$stateParams.tplId;
	
	var inserter = new Req.POST({ resource: $scope.resource });
	var deleter = new Req.DELETE({ resource: $scope.resource });
	
	$scope.reload = $scope.page.loader('vehicle/bs/tpl/{tplId}/{pageIndex}/{pageSize}/page'.format({tplId:$scope.tplId}));
	$scope.$on('pageIndex', function (event, p) { $scope.reload(p, $scope.queryMap); });
	$scope.reload(1);
	$scope.queryMap = {};
	$scope.query = function () { $scope.reload(1, $scope.queryMap); };

	
    // 关联
    $scope.write = function() {        
        var modalInstance = $modal.open({
            templateUrl: 'template/bus/vehicleShift/writeModal.html?v=0f96653797',
            controller: 'BusVehicleShiftModalCtrl',
            size: 'lg',
            resolve: {
                param: function() { return {};}
            }
        });

        modalInstance.result.then(function(param) {
            inserter.fields = param.data;
            inserter.resource = 'vehicle/bs/tpl/{tplId}/insert'.format({tplId:$scope.tplId});
            $scope.page.add(inserter, $scope.reload);
        });
    };

	//删除
	$scope.del = function (size, current_data, submit_type) {
		var modalInstance = $scope.delModal(size, current_data, submit_type);
		modalInstance.result.then(function (param) {
			if (param.type == 'delete') {
				deleter.id = param.data.id;
				deleter.resource = 'vehicle/bs/tpl/' + deleter.id + '/delete';
				$scope.page.del(deleter, $scope.reload);
			}
		});
	};

});
